<?php


namespace app\api\controller;
Use \app\api\model\Feedback as FeedbackModel;
use think\Controller;
use think\Request;

class Feedback extends Controller
{
    protected $middleware = ['Auth'];
    /**
     * 添加建议反馈
     */
    public function addFeedback(Request $request){
        $data['user_id'] = $request->userId;
        $data['feedback_title'] = input("?post.title") ? input("post.title") : "";
        $data['feedback_content'] = input("?post.content") ? input("post.content") : "";
        $data['status'] = 1;
        if($data['feedback_title'] == "" || $data['feedback_content'] == ""){
            return fail(INVALID_REQUEST, '标题或内容为空');
        }
        $result = FeedbackModel::addFeedback($data);
        if($result){
            return  success($result);
        }else{
            return  fail(INVALID_REQUEST, '添加失败');
        }

    }

    /**
     * 查看建议反馈列表
     */
    public function FeedbackList(Request $request){
        $groupid = $request->groupId;
        if($groupid != 10004){
            return  fail(INVALID_REQUEST, '权限不足');
        }
        $result = FeedbackModel::queryFeedbackList();
        if($result){
            return  success($result);
        }else{
            return  fail(DATA_NOT_EXIST, '查询失败');
        }
    }

    /**
     * 根据id查询反馈内容
     */
    public function feedbackDetail(Request $request){
        $groupid = $request->groupId;
        if($groupid != 10004){
            return  fail(INVALID_REQUEST, '权限不足');
        }
        $id = input("?get.id") ? input("get.id") : 0;
        if($id == 0){
            return fail(INVALID_REQUEST, '参数错误');
        }
        $result = FeedbackModel::queryFeedbackById($id);
        if($result){
            return  success($result);
        }else{
            return  fail(DATA_NOT_EXIST, '查询失败');
        }
    }
}